﻿function StaffTimeTestController($scope, service, $routeParams, $location, $http) {

    $scope.rowsData = [];

    $scope.myFilter = {
        RowStatus: ""
    }; // $scope.myOrderBy = "true";

    //get id
    $http.get("api/StaffTest/", {})
        .success(function(data) {

            //data[0]
            $scope.rowsData = data;
        })
        .error(function(err) {

            console.log("error", err);
        });

    $scope.Status = $scope.rowsData.RowStatus;

    //Click Eidt
    $scope.edit = function(id) {
        // URL: "#/StaffTimeTestEdit";
        $location.path("/StaffTimeTestEdit/" + id).search(
            {
                RowStatus: "b"
            }
        );

    }; // Click on table row
    $scope.getRowData = function(row) {
        angular.extend($scope, row);
    }; // update function
    $scope.update = function() {
        var StaffObj = {
            Id: $scope.Id,
            StaffId: $scope.StaffId,
            StampDate: $scope.StampDate,
            UpdateTime: $scope.UpdateTime,
            Remark: $scope.Remark,
            CheckIn: $scope.CheckIn,
            CheckOut: $scope.CheckOut,
            GoOut: $scope.GoOut,
            TurnBack: $scope.TurnBack,
            StartBreakTime: $scope.StartBreakTime,
            EndBreakTime: $scope.EndBreakTime,
            RowStatus: $scope.RowStatus
        };
        $http.put("api/StaffTest/", StaffObj)
            .success(function(data) {
                console.log("success", data);
                $scope.rowsData.push(data);
            })
            .error(function(err) {
                console.log("error", err);
            });
    }; //Select funtion

    //save function
    $scope.save = function() {
        var StaffObj = {
            StaffId: $scope.StaffId,
            StampDate: $scope.StampDate,
            UpdateTime: $scope.UpdateTime,
            Remark: $scope.Remark,
            CheckIn: $scope.CheckIn,
            CheckOut: $scope.CheckOut,
            GoOut: $scope.GoOut,
            TurnBack: $scope.TurnBack,
            StartBreakTime: $scope.StartBreakTime,
            EndBreakTime: $scope.EndBreakTime,
            RowStatus: $scope.RowStatus
        };
        $http.post("api/StaffTest/", StaffObj)
            .success(function(data) {
                console.log("success", data);
                $scope.rowsData.push(data);
            })
            .error(function(err) {
                console.log("error", err);
            });
    };
}